/*
 * MainMenuPanel.java
 *
 * Created on January 6, 2007, 7:56 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.sf.iSnake.UI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.sf.iSnake.configuration.iSnakeConfiguration;

/**
 *
 * @author thelinuxmaniac
 */
public class MainMenuPanel extends JPanel{
    
    private static iSnakeConfiguration conf;
    public static Color MainMenuPanelBackgroundColor = Color.BLACK;
    
    private JPanel menuItemPicturePanel;
    private JPanel menuDescriptionPicturePanel;
    
    private JButton menuItemButtons[];
    
    public static String[] menuItemsString = {   "Multiplayer Server Mode",
                                            "Multiplayer Client Mode",
                                            "Standalone Single Player",
                                            "About",
                                            "Exit"};
    
    public static String[] menuItemsCommand = {   "multiplayer_server_mode",
                                            "multiplayer_client_mode",
                                            "standalone_mode",
                                            "about",
                                            "exit"};
    private static Character[] menuItemsMnemonic = {'S','C','T','A','X'};
    public static String panelName = "MainMenuPanel";
    
    
    /** Creates a new instance of MainMenuPanel */
    public MainMenuPanel(iSnakeConfiguration conf) {
        setLayout(new BorderLayout());
        this.conf = conf;
        setBackground(MainMenuPanelBackgroundColor);
        
//        JPanel menuItemsPanel = new JPanel(new GridBagLayout());
        JPanel menuItemsPanel = new JPanel(new GridLayout(5,1,0,0));
        menuItemsPanel.setPreferredSize(new Dimension(400,300));
        menuItemsPanel.setBackground(conf.MenuItemBackgroundColor);
        menuItemButtons = new JButton[menuItemsString.length];
        Font f = new Font(conf.MenuItemsFont,Font.PLAIN,conf.MenuItemsFontSize);
        
        for(int i=0;i<menuItemsString.length;i++)   {
            menuItemButtons[i] = new JButton(menuItemsString[i]);
            menuItemButtons[i].setFont(f);
            menuItemButtons[i].setForeground(conf.MenuItemForegroundColor);
            menuItemButtons[i].setBackground(conf.MenuItemBackgroundColor);
            
            menuItemButtons[i].setMnemonic(menuItemsMnemonic[i]);
            menuItemButtons[i].setBorder(null);
            menuItemButtons[i].setBorderPainted(false);
            menuItemButtons[i].setContentAreaFilled(true);
            menuItemButtons[i].setRolloverEnabled(false);
            menuItemButtons[i].setActionCommand("from_MainMenuPanel_to_"+menuItemsCommand[i]);
            menuItemsPanel.add(menuItemButtons[i]);
//            menuItemsPanel.add(menuItemButtons[i],new GBC(GBC.RELATIVE,i).setFill(GBC.BOTH).setAnchor(GBC.WEST).setWeight(1,1).setIpad(160,0));
        }
        
        // used for placing picture of menuItem, that appears when mouse rolls over the menuItem
        JPanel menuItemPicturePanel = new JPanel();
        menuItemPicturePanel.setBackground(conf.MenuItemBackgroundColor);
        menuItemPicturePanel.setPreferredSize(new Dimension(300,300));
        menuItemPicturePanel.add(new JLabel("Menu Picture goes here"));
        
        // used for proper placement of components
        JLabel dummyEast = new JLabel("");
        dummyEast.setPreferredSize(new Dimension(100,300));
        
        // used for proper placement of components
        JLabel dummyNorth = new JLabel("");
        dummyNorth.setPreferredSize(new Dimension(800,140));        // height of logo=120px and 20px for padding purpose
        
        // used for description of menuItem, that appears when mouse rolls over the menuItem
        JPanel menuItemDescriptionPanel = new JPanel();
        menuItemDescriptionPanel.setBackground(conf.MenuItemBackgroundColor);
        menuItemDescriptionPanel.setPreferredSize(new Dimension(800,160));
        menuItemDescriptionPanel.add(new JLabel("Menu Description goes here"));
        
        add(dummyNorth,BorderLayout.NORTH);
        add(dummyEast,BorderLayout.EAST);
        add(menuItemDescriptionPanel,BorderLayout.SOUTH);
        add(menuItemPicturePanel,BorderLayout.WEST);
        add(menuItemsPanel,BorderLayout.CENTER);
    }
    
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.drawImage(conf.getISnakeLogoSmall(),10,10,null);
    }
    
    public static String getPanelName() {
        return panelName;
    }

    public static void setPanelName(String aPanelName) {
        panelName = aPanelName;
    }

    public JButton getMenuItemButtons(int index) {
        return menuItemButtons[index];
    }
}